package sms

import (
	"myai/core/types"
	logger2 "myai/logger"
	"strings"
)

var log = logger2.GetLogger()

// ServiceManager 管理不同的短信接口实现
type ServiceManager struct {
	// 发送短信接口
	handler Service
}

func NewSendServiceManager(config *types.AppConfig) (*ServiceManager, error) {
	active := Bao
	if config.SMS.Active != "" {
		// 转大写
		active = strings.ToUpper(config.SMS.Active)
	}
	var handler Service
	// 根据配置选择不同的短信发送实现
	switch active {
	case Ali:
		client, err := NewAliYunSmsService(config)
		if err != nil {
			return nil, err
		}
		handler = client
		break
	case Bao:
		handler = NewBaoSmsService(config)
		break
	}
	return &ServiceManager{
		handler: handler,
	}, nil
}

func (m *ServiceManager) GetService() Service {
	return m.handler
}
